
var app = getApp();
var applet_park_api_url = app.globalData.applet_park_api_url;
var applet_park_api_url_imgUrl = app.globalData.applet_park_api_url_imgUrl;
//获取应用实例

Page({
  data: {
    motto: 'Hello World',
    nickName:'',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    imgUrl:applet_park_api_url_imgUrl,
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    // 查看是否授权
    wx.getSetting({
      success: function (res) {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          wx.getUserInfo({
            success: function (res) {
              
            }
          })
        }
      }
    })
  },
  toPatrol:function(){
    var id = wx.getStorageSync("id");
    if (!id){
      wx.showToast({
        title: '请先登录',
      })
      return

    }
    wx.navigateTo({
      url: '../patrol_list/patrol_list',
    })
  },
  toLogin:function(){
    wx.navigateTo({
      url: '../login/login',
    })
    // wx.navigateTo({
    //   url: '../loginidentityList/loginidentityList',
    // })
  },
  gomyapply(){
    wx.navigateTo({
      url: '../myapply/myapply',
    })
  },
  // 点击授权按钮，返回的信息
  getUserInfo: function (res) {

    var userInfo = JSON.parse(res.detail.rawData);
    
    if (userInfo) {
      //将用户信息赋值给app.globalData.userInfo
      for (var pro in userInfo) {
        app.globalData.userInfo[pro] = userInfo[pro];
      }
      //将用户信息缓存下来
      wx.setStorageSync('USER_INFO', userInfo);
      //调用
      wx.navigateTo({
        url: '../wxauthorization/wxauthorization',
      })
    } else {
      wx.showToast({
        title: '获取用户信息失败',
        icon: 'none'
      });
    }
  },
  bindGetUserInfo:function(e){
    
  },
  onShow(){
    var userInfo = wx.getStorageSync("USER_INFO");
    var nickName = wx.getStorageSync("nickName");
    this.setData({
      userInfo: userInfo,
      nickName: nickName
    });
   
  },
  gotoProperty(){
    wx.navigateTo({
      url: '../property/property',
    })
  },
  gotomyidentityList(){
    var id = wx.getStorageSync("id");
    // if (!id) {
    //   wx.showToast({
    //     title: '请先登录',
    //   })
    //   return

    // }
    wx.navigateTo({
      url: '../myidentityList/myidentityList',
    })
  },

})
